package com.xuecheng.teaching.controller;


import com.xuecheng.commons.model.dto.PageRequest;
import com.xuecheng.commons.model.dto.PageWork;
import com.xuecheng.commons.model.dto.WorkDto;
import com.xuecheng.commons.model.dto.WorkQuestDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.WorkVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.teaching.domain.Work;
import com.xuecheng.teaching.service.WorkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 作业前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/work")
public class WorkController {

    @Autowired
    private WorkService workService;

    //分页条件查询课程计划作业列表
    /*
     *   POST list
     *   请求参数  Query  WorkDto
     *   返回值 ResponseResult<WorkVo>
     * */
    @PostMapping("/list")
    public ResponseResult<WorkVo> list(PageRequest request) {
        return workService.findAll(request);
    }
//教学计划绑定作业选择

//新增作业
    @PostMapping
    public ResponseResult saveWord(@RequestBody WorkQuestDto dto) {
        return workService.saveWork(dto);
    }
    //删除作业

    @DeleteMapping("/{workId}")
    public ResponseResult deleteWork(@PathVariable("workId") Integer workId) {
       workService.removeById(workId);
        return ResponseResult.okResult();
    }
    //根据id查询作业
    @GetMapping("/{wordId}")
    public ResponseResult<WorkVo>findWordById(@PathVariable("wordId")Integer workId) {
        Work work = workService.getById(workId);
        WorkVo workVo = BeanHelper.copyProperties(work, WorkVo.class);
        workVo.setTitle(work.getTitle());
        workVo.setQuestion(work.getQuestion());
        workVo.setWorkId(workId);

        return ResponseResult.okResult(workVo);
    }

}
